<template>
  <a-card class="addHYmodel">
    <a-modal style="padding: 0;"
      title="题目跳转管理"
      :width="1200"
      :visible="modalMisible"
      :plain="true"
      :model="forms"
      @ok="submitOk"
      @cancel="modalMisible=false"
    >
      <a-card :bordered="false">
        <div class="table-page-search-wrapper">
          <a-form layout="inline" :model='form' @keyup.enter.native="searchQuery">
            <a-row :gutter="24" v-for="(item1,index) in forms" :key="index">
              <a-col :xl="5" :lg="7" :md="8" :sm="24">
                <a-form-item label="当前题号" :required="true" hasFeedback>
                  <a-input v-model="item1.questionNumber" placeholder="请输入当前题号" type="input"  />
                </a-form-item>
              </a-col>
              <a-col :xl="5" :lg="7" :md="8" :sm="24">
                <a-form-item :labelCol="labelCol" label="答案" :required="true" hasFeedback>
                  <a-input v-model="item1.answerNumber" placeholder="答案" type="input"/>
                </a-form-item>
              </a-col>
              <a-col :xl="5" :lg="7" :md="8" :sm="24">
                <a-form-item :labelCol="labelCol" label="跳转到" :required="true" hasFeedback>
                  <a-input v-model="item1.jumpQuestion" placeholder="跳转到" type="input"/>
                </a-form-item>
              </a-col>
              <a-col :xl="2" :lg="7" :md="8" :sm="24">
                <a-button type="danger" @click="deleteHYBtn(index,item1.id)" icon="delete">删除该条数据</a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :xl="5" :lg="7" :md="8" :sm="24">
                <a-button type="primary" @click="addHYBtn" icon="plus">添加跳转</a-button>
              </a-col>
            </a-row>
          </a-form>
        </div>
      </a-card>
    </a-modal>

  </a-card>
</template>

<script>
import { httpAction, getAction,putAction } from '@api/manage'
import JDate from '@/components/jeecg/JDate'
export default {
  name: '题目跳转管理-添加',
  components: {
    JDate,
  },
  inject: ['reload'],

  data() {
    return {
      title: '题目跳转管理',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCols: {
        xs: { span: 12 },
        sm: { span: 8 },
      },
      wrapperCols: {
        xs: { span: 12 },
        sm: { span: 10 },
      },
      modalMisible: false,
      forms:[
        {
          questionNumber:'',
          parentId:'',
          templateId:'',
          answerNumber:'',
          jumpQuestion:''
        }
      ],
      hospitals:{},  //医院信息
      form: this.$form.createForm(this),
      url: {
        add: "/questionAll/questionAll/addRules"
      },
      templateId:''
    }
  },
  created() {
    this.viewShow();
  },
  methods: {
    //删除该跳转del(index,id)
    deleteHYBtn(index,id){
      this.forms.splice(index,1);
    },
    // 添加跳转
    addHYBtn(){
      this.forms.push({
        questionNumber:'',
        parentId:'',
        templateId:'',
        answerNumber:'',
        jumpQuestion:''
      })
    },
    viewShow(record) {
      this.templateId = record.templateId;
      console.log('0',this.templateId)
      var param = {"doctorId":record.id};

      getAction(this.url.add,param).then(res => {
        console.log(res.result)
        this.hospitals = res.result.hospitals;
        this.forms.department = res.result.doctor.department;
      })

      this.modalMisible = true
    },
    //选择医院
    selectHospital(hospital){
      this.forms.registerHospitalId = hospital.id;
    },

    submitOk () {
      console.log("submitOk1",this.forms)
      this.forms.forEach(item => {
        item.templateId = this.templateId
        item.parentId = item.questionNumber
      });
      console.log("submitOk2",this.forms)
      if(this.checkForms(this.forms)){
        httpAction(this.url.add, this.forms,'post').then((res)=>{
          if(res.code === 200){
            this.$message.success(res.message)
            this.reload()
          }else{
            this.$message.warning(res.message)
          }
        }).catch((error)=>{
          console.log(error);
        })
      }
    },

    //校验表单信息
    checkForms(forms){
      if(forms.registerHospitalId == ''){
        this.$message.warning("请选择挂号医院！")
        return false
      }else if(forms.type == '') {
        this.$message.warning("请选择号种类型！")
        return false
      }else if(forms.visitTime == ''){
        this.$message.warning("请选择日期！")
        return false
      }else if(forms.visitPart == ''){
        this.$message.warning("请选择时间段！")
        return false
      }else{
        return true
      }
    }
  }
}
</script>

<style lang="less">
  .addHYmodel{
    padding: 0;
    & .ant-modal-body {
          padding: 0!important;
      }
  }
  .ant-modal-body {
          padding: 0 !important;
      }
  .ant-input-number {
    margin-right: 20px;
    width: 360px;
  }

  .ant-btn-danger{background-color: #ff4d4f; border-color: #ff4d4f;}
  .ant-form.ant-form-inline > .ant-row:nth-child(even){height:30px;background:#efefef;}
  // .ant-row:nth-child(even){height:30px;background:#00f;}
  // .ant-form-item:nth-child(odd){background: #eee;}
</style>